package libs
{
   import flash.display.Sprite;
   import flash.media.Sound;
   import flash.media.SoundChannel;
   import flash.media.SoundLoaderContext;
   import flash.media.SoundTransform;
   import flash.net.URLRequest;
   //--------------------------
   public class Sonido extends Sprite {      
      private var so:Sound;
      private var url:URLRequest;
      private var buffer:SoundLoaderContext;
      private var ini:Number;
      private var loop:Number;
      private var channel:SoundChannel;
      private var reproduciendo:Boolean = true;
      private var trans:SoundTransform = new SoundTransform(1, 0);
	  private var panCounter:Number = 0;
	  private var vol:Number = 0;

      
      
      //----------------------
      public function Sonido(qUrl:String, qBuffer:Number, qIni:Number, qLoop:Number) {
         url = new URLRequest(qUrl);
         buffer = new SoundLoaderContext(qBuffer*1000);
         ini = qIni*1000;
         loop = (qLoop >= 0) ? qLoop : int.MAX_VALUE;
         so = new Sound(url, buffer);
         channel =so.play(ini, loop);
         
         
      }
      
      public function startStop():void
      {
      	if ( reproduciendo )
      		channel.stop();
      	else
      		channel = so.play();
		reproduciendo = (!reproduciendo);  
      }
      
      public function siguienteEstado():String
      {
      	if ( reproduciendo )
      		return "Stop";
      	else
      		return "Start";      	
      }
      
		public function volumen(modifica:int):void
		{
		 	
		 	vol = trans.volume + (modifica/10);
		 	
		 	if (vol >= 0)
		 	{
		 	trans.volume = vol;
		 	channel.soundTransform = trans;		    
		  	}
		    
		}
	
      
   }

}